package com.lx.algorithm.structure;

import java.util.Stack;

/**
 * Description: 用栈实现队列
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-02 17:42:28
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-02     张李鑫                     1.0         1.0 Version
 */
public class TwoStacksImplementQueue {
    private Stack<Integer> pushStack = new Stack<>();
    private Stack<Integer> popStack = new Stack<>();


    public void add(Integer value) {
        this.pushStack.push(value);
    }


    public Integer pop() {
        if (pushStack.empty() && pushStack.empty()) {
            throw new RuntimeException("Queue is empty!");
        }
        if (popStack.isEmpty()) {
            importValue();
        }
        return popStack.pop();
    }

    public void importValue() {
        while (!pushStack.isEmpty()) {
            popStack.push(pushStack.pop());
        }
    }

    public static void main(String[] args) {
        TwoStacksImplementQueue test = new TwoStacksImplementQueue();
        test.add(1);
        test.add(2);
        test.add(3);
    }
}
